<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>商城首页</title>
    <jsp:include page="../common/header.jsp"/>
   	<jsp:include page="../../common/validform.jsp"/>
    <jsp:include page="../../common/layer.jsp"></jsp:include>
    <script type="text/javascript" src="${pathUrl}/public/js/PCASClass.js"></script>
	<style type="text/css">
		.btn-address{
	    width: 120px;
	    height: 30px;
	    background-color: #4bbb2f;
	    display: block;
	    line-height: 30px;
	    text-align: center;
	    color: #fff;
		}
	</style>
</head>
<body>
<%@include file="../common/top.jsp" %>
<form action="${pathUrl}/home/order/submitOrder" method="post" id="mainForm">
<input type="hidden" id="goodsId" name="goodsId" value="${goods.id}">
<input type="hidden" id="goodsNum" name="go_num" value="${goodsNum}">
<div class="section">
    <div class="cart-head">
        <h2>填写订单</h2>
        <div class="cart-setp">
            <ul>
                <li class="first active">
                    <div class="progress">
                        <span>1</span>
                        放进购物车
                    </div>
                </li>
                <li class="active">
                    <div class="progress ">
                        <span>2</span>
                        填写订单信息
                    </div>
                </li>
                <li class="last">
                    <div class="progress">
                        <span>3</span>
                        支付/确认订单
                    </div>
                </li>
            </ul>
        </div>
    </div>

</div>

<div class="section">
   <div class="cart-box">
       <h2 class="slide-tit">
           <span>1、收货地址</span>
       </h2>
   </div>
	<ul id="userAddress" class="address-list">
	<a onclick="alertFrame(${goods.id}, ${goodsNum})" class="btn-address">新增收货地址</a>
	<c:forEach items="${addressList}" var="ads">
             <li>
	             <label>
	                 <input name="user_book_id" type="radio" value="${ads.id}" >
	                 <span>${ads.province},${ads.city},${ads.area}${ads.address}(${ads.userName}收)</span>
	                  <span>手机号码：</span><em>${ads.phone}</em> 
	             </label>
             </li>
             </c:forEach>
          </ul>

    <h2 class="slide-tit">
        <span>2、商品清单</span>
    </h2>
 
    <table width="100%" align="center" class="cart-table" border="0" cellspacing="0" cellpadding="8">
        <tbody>
        <tr>
            <th align="left" colspan="2">商品信息</th>
            <th width="84" align="left">单价</th>
            <th width="104" align="center">数量</th>
            <th width="104" align="left">金额(元)</th>
        </tr>
        <tr>
            <td width="68">
                <a target="_blank" href="#">
                    <img onerror="this.src='${pathUrl }/public/images/nopic.png'"  src="${pathUrl}${goods.goodsImg}" class="img">
                </a>
            </td>
            <td>
                <a target="_blank" href="#">${goods.goodsName}</a>
                <p class="stxt"></p>
            </td>
            <td>
                ￥${goods.sellPrice}
            </td>
            <td align="center">
                <div class="buy-box">
                    <span class="goodsQuantity">${goodsNum}</span>
                </div>
            </td>
            <td>
                <span class="red">
                    ￥<label name="amountCount">${goodsNum*goods.sellPrice}</label>
                </span>
            </td>

        </tr>
        </tbody>
    </table>
    <h2 class="slide-tit">
        <span>3、结算信息</span>
    </h2>

    <div class="buy-foot clearfix">
        <div class="left-box">
            <dl>
                <dt>订单备注(100字符以内)</dt>
                <dd>
                    <textarea name="message" class="input" style="height:35px;"></textarea>
                </dd>
            </dl>
        </div>
        <div class="right-box">
            <p>
                商品 <label class="price">${goodsNum}</label> 件&nbsp;&nbsp;&nbsp;&nbsp;
                商品金额：￥<label id="goodsAmount" class="price">${goods.sellPrice}</label> 元&nbsp;&nbsp;&nbsp;&nbsp;
            </p>
            <p class="txt-box">
                应付总金额：￥<label id="totalAmount" class="price">${goodsNum*goods.sellPrice}</label>
            </p>
            <p class="btn-box">
                <input id="sub" type="button" value="确认提交"   class="btn submit"/>
            </p>
        </div>
    </div>
</div>
</form>

<jsp:include page="../../common/laypage.jsp"/>
<script type="text/javascript">
$("#mainForm").Validform();


$(function(){
	$("input[name='user_book_id']").eq(0).prop("checked",true);

    $(function() {
        $("#sub").click(function () {
            var addressList = $("#userAddress input:checked");
            var addId = addressList.eq(0).val();
            var message = $("textarea[name='message']").val();
            var goodsId = $("#goodsId").val();
            var goodsNum = $("#goodsNum").val();

            if (addressList.length < 1) {
                alert("请新增一个收货地址！");
                return false;
            }
            alert(goodsNum);
            $.post("${pathUrl}/home/order/pay",{addId: addId, message: message, goodsId: goodsId, goodsNum: goodsNum},function(result){

                if(result.status==1){
                    alert(result.msg);
                    window.location.href="${pathUrl}/home/cart/toPay"
                } else if (result.status=-1) {
                    alert(result.msg);
                    window.location.href="${pathUrl}/home/center/recharge";
                }
            });
        });
    });


});

//弹窗新增地址
function alertFrame(id, num) {
    alert('${pathUrl}/home/order/addAddress?goodsId='+id+'&go_num='+num);
    layer.open({
        type: 2,
        title: '',
        shadeClose: true,
        shade: false,
        maxmin: true, //开启最大化最小化按钮
        area: ['930px', '600px'],
        content: '${pathUrl}/home/order/addAddress?goodsId='+id+'&go_num='+num
    });
}
</script>
</body>
</html>